﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace PH.Web.Management.Filters
{
    public sealed class CurrentSchoolAttribute : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (PH.Web.Global.WebContext.CurrentSchool == null)
            {
                filterContext.HttpContext.Response.Redirect("/Accounts/User/Login");
                filterContext.Result = new EmptyResult();
            }
            else
                filterContext.Controller.ViewBag.SchoolGuid = PH.Web.Global.WebContext.CurrentSchool.Guid;
        }
    }
}